import { createSlice, PayloadAction } from "@reduxjs/toolkit";
import { AuthState } from "@/store/interface";
import { useCreateActionFunction } from "@/store/hooks";
import { SettingType } from "@/enums";

const initialState: AuthState = {
	currentUser: {},
	settingMaps: {
		[SettingType.GOODS_STATUS_LABEL]: []
	}
};

const AuthSlice = createSlice({
	name: "auth",
	initialState,
	reducers: {
		setCurrentUser(state: AuthState, { payload }: PayloadAction<any>) {
			state.currentUser = payload;
		},
		setSettingMaps(state: AuthState, { payload }: PayloadAction<any>) {
			state.settingMaps[payload.type] = payload.data;
		}
	}
});
export const useAuthActionFunction = useCreateActionFunction(AuthSlice);
export const { setCurrentUser, setSettingMaps } = AuthSlice.actions;
export default AuthSlice.reducer;
